package com.example.csupermaket.controller;


import com.example.csupermaket.exception.ServiceException;
import com.example.csupermaket.pojo.dto.UserAddNewDTO;
import com.example.csupermaket.pojo.dto.UserLoginDTO;
import com.example.csupermaket.pojo.vo.UserStandardVO;
import com.example.csupermaket.service.IUserService;
import com.example.csupermaket.web.JsonResult;
import com.example.csupermaket.web.ServiceCode;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "02.用户管理模块")
public class UserController {

    @Autowired
    private IUserService userService;

    // http://localhost:9081/admins/login
    @ApiOperation("用户登录")
    @ApiOperationSupport(order = 10)
    @PostMapping("/login")
    public JsonResult login(UserLoginDTO userLoginDTO) {
        log.debug("开始处理【用户登录】的请求，参数：{}", userLoginDTO);

        userService.login(userLoginDTO);

        return JsonResult.ok();

    }

    @PostMapping("/add-new")
    @ApiOperation("01.添加用户")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(UserAddNewDTO userAddNewDTO){

        userService.addNew(userAddNewDTO);
        return JsonResult.ok();

    }

    @PostMapping("/delete")
    public void delete(){
        String message = "";
        throw new ServiceException(ServiceCode.OK,message);
    }


    @PostMapping("/update")
    @ApiOperation("03.修改修改用户信息")
    public void update(){
        String message = "";
        throw new ServiceException(ServiceCode.OK,message);
    }

    @GetMapping("/{username}")
    @ApiOperation("根据用户名查询用户相关信息")
    @ApiOperationSupport(order = 410)
    public JsonResult getStandardByName(@PathVariable String username){
        UserStandardVO queryResult = userService.getStandardByName(username);
        return JsonResult.ok(queryResult);
    }


}
